package com.aios.dao;

import com.aios.entity.UserGroup;
import com.aios.entity.UserGroupExample;
import com.aios.entity.mapper.UserGroupHasUsers;

import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

public interface UserGroupMapper {

	int countByExample(UserGroupExample example);

	int deleteByExample(UserGroupExample example);

	int deleteByPrimaryKey(Integer id);

	int insert(UserGroup record);

	int insertSelective(UserGroup record);

	List<UserGroup> selectByExample(UserGroupExample example);

	UserGroup selectByPrimaryKey(Integer id);

	int updateByExampleSelective(@Param("record") UserGroup record,
			@Param("example") UserGroupExample example);

	int updateByExample(@Param("record") UserGroup record,
			@Param("example") UserGroupExample example);

	int updateByPrimaryKeySelective(UserGroup record);

	int updateByPrimaryKey(UserGroup record);

	@Select("SELECT * FROM user_group WHERE STATUS = #{status} ORDER BY SORT_ORDER")
	@ResultMap(value = "MiniResultMap")
	List<UserGroup> findAllByStatus(@Param("status") Integer status);

	@Select("SELECT * FROM user_group WHERE GROUP_NAME = #{userGroupName}")
	@ResultMap(value = "MiniResultMap")
	List<UserGroup> findByGroupName(@Param("userGroupName") String userGroupName);

	@Select("SELECT * FROM user_group WHERE STATUS = #{status} ORDER BY SORT_ORDER")
	@ResultMap(value = "UserGroupHasUsersResultMap")
	List<UserGroupHasUsers> findUsersForGroups(@Param("status") Integer status);

	@Select("SELECT * FROM user_group WHERE ID = #{id}")
	@ResultMap(value = "UserGroupHasUsersResultMap")
	UserGroupHasUsers findByIdWithUsers(@Param("id") Integer id);

	@Select("SELECT COUNT(*) FROM user_group WHERE STATUS = #{status}")
	Integer countAllByStatus(@Param("status") Integer status);

	@Select("SELECT * FROM user_group WHERE STATUS = #{status} ORDER BY SORT_ORDER LIMIT #{start}, #{size}")
	@ResultMap(value = "UserGroupHasUsersResultMap")
	List<UserGroupHasUsers> findListPaginated(@Param("status") Integer status,
			@Param("start") Integer start, @Param("size") Integer size);

	@Select("SELECT * FROM user_group WHERE GROUP_NAME = #{userGroupName} AND ID != #{id}")
	@ResultMap(value = "MiniResultMap")
	List<UserGroup> findGroupNameNotWithId(
			@Param("userGroupName") String groupName, @Param("id") Integer id);

}